﻿import mx.rpc.http.HTTPService;
import mx.rpc.events.ResultEvent;

import mx.managers.PopUpManager;
import mx.collections. *;
import mx.controls. *;
import com.esri.ags.Map;
import com.esri.ags.geometry.Extent;
import com.uprr.app.tnm.model.Model;
import com.uprr.app.tnm.events.AppEvent;
import com.uprr.app.tnm.events.EventBus;

import com.adobe.serialization.json.JSON

public var winId:String;
public var mapSvc:String;


private function init():void {
	EventBus.addEventListener (AppEvent.TASK_RESET, taskReset);
}

private function handleCreationComplete () : void 
{
	// Center the TitleWindow container
	// over the control that created it.
	PopUpManager.centerPopUp (this);
}


// when something goes wrong for all HTTP services
private function serviceFaultHandler (event : Event) : void
{
	var errorEvent : AppEvent = new AppEvent (AppEvent.APP_ERROR);
		errorEvent.data = " ???? ";
		errorEvent.dispatch ();
}


private function closeWin():void {
	PopUpManager.removePopUp(this);
	var taskWinCloseEvent : AppEvent = new AppEvent (AppEvent.TASK_WINCLOSE);
		taskWinCloseEvent.data = winId;
		taskWinCloseEvent.dispatch ();
}

/**
 * Close this task, if map service is changed, and this task is not applicable.
 * @param	e
 */
public function taskReset(e : AppEvent):void {
	var svc:String = e.data as String;
	//Alert.show("svc:" + svc+"task svc:"+mapSvc);
	if (svc != mapSvc && mapSvc != 'ALL')
		closeWin();
}